
<%@page import="com.epcs.util.EpcsDateTimeUtil"%>
<%@page import="com.epcs.model.dto.Event"%>
<%@page import="java.util.List"%>
<%@page import="com.epcs.model.bo.EventBO"%>
<%@page import="org.apache.struts2.dispatcher.SessionMap"%>
<%@page import="com.epcs.model.dto.Account"%>
<%@page import="com.epcs.model.bo.FollowingBO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%
	FollowingBO followBO = new FollowingBO();
	Account account = (Account) session.getAttribute("USER_INFO");
	EventBO newEventBO = new EventBO();
	List<Integer> eventIdList = followBO.getEventIdListByAccount(account);
	List<Event> eventList = newEventBO.getCommingEvent(eventIdList, 0, 3);
	if(eventList != null){
		for (int i = 0 ;i < eventList.size() ; i ++ ){
			Event event = eventList.get(i);
			boolean isTomorrow = EpcsDateTimeUtil.checkDateTimeIsTomorrow(event.getStartTime());
			boolean isToday = EpcsDateTimeUtil.checkDateTimeIsToday(event.getStartTime());
			if(isToday){
				long time = EpcsDateTimeUtil.compareCurrentTimeWithString(event.getStartTime());
				
				if(time<60){
					String remainTime = "Còn khoảng " + String.valueOf(time)+"p";
					event.setStartTime(remainTime);
				}
				else{
					long temp =(time/60);
					String remainTime = "Còn khoảng " + String.valueOf(temp)+ "h"+ String.valueOf(temp%60)+"p";
					event.setStartTime(remainTime);
				}
				
			}
			else if(isTomorrow){
				if(event.getIsAllDayEvent()){
					String date = "Ngày mai";
					event.setStartTime(date);
				}else{
					String date = EpcsDateTimeUtil.convertDateTimeWithPattern(event.getStartTime(), "HH'h' mm,") +" ngày mai";
					event.setStartTime(date);
				}
			}else{
				long time = EpcsDateTimeUtil.compareCurrentTimeWithString(event.getStartTime());
				long temp =(time/60);
				if(temp<24){
					String remainTime = "Còn khoảng " + String.valueOf(temp)+ "h"+ String.valueOf(temp%60)+"p";
					event.setStartTime(remainTime);
				}else{
					if(event.getIsAllDayEvent() == true){
						String inpStartTime = event.getStartTime();
						String outStartTime = EpcsDateTimeUtil.convertDateTimeWithPattern(inpStartTime, "dd-MM-yyyy");
						event.setStartTime(outStartTime);
					}else{
						String inpStartTime = event.getStartTime();
						String outStartTime = EpcsDateTimeUtil.convertDateTimeWithPattern(inpStartTime, "HH'h' mm, dd-MM-yyyy");
						event.setStartTime(outStartTime);
					}
				}
			}	
		}
	}
	request.setAttribute("COMMING_EVENT_LIST", eventList);
%>
<s:set var="comming_event_list" value="%{#request.COMMING_EVENT_LIST}" />
  <div class="accordion-group">
    <div class="accordion-heading">      
      	<a class="btn-info btn"  data-toggle="collapse" data-parent="#dropDownSidebar" href="#collapseContent"
      		style="width : 100%;">
       		<i class="icon-lightbulb"></i> Sự kiện sắp tới
   		</a>
    </div>
    <div id="collapseContent" class="accordion-body collapse in">
      <div class="accordion-inner">
       <div class="panel panel-primary" style="border-radius: 0px;">
        <s:if test="%{#comming_event_list.isEmpty() == false}">
			<s:iterator var="comming_event_item" value="%{#comming_event_list}">
				<div class="row deliverEvent_sidebar"
					style="margin-top: 5px; padding-bottom: 8px;">
					<div class="row">
						<div class="col-md-12">
							<a href="PublicEventDetail.do?id=${comming_event_item.eventId}">
								<span style="font-size: 14">${comming_event_item.title}</span>
							</a>
						</div>
					</div>
					<div class=" row invisibleLine"></div>
					<div class="row">
						<div class="col-md-5">
							<b>Diễn ra vào: </b>
						</div>
						<div class="col-md-7">${comming_event_item.startTime}</div>
					</div>
				</div>
			</s:iterator>
			</s:if>
			<s:else>
				<div class="row deliverEvent_sidebar"
					style="margin-top: 5px; padding-bottom: 8px;">
					<div class="row">
						<div class="col-md-12">
							Không có sự kiện nào!
						</div>
					</div>					
				</div>
			</s:else>
		</div>
      </div>
    </div>
  </div>